#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 3e5+10;

int h[N],cnt,deg[N],m,n,f[N],u[N],v[N];
bool cannot[N];
struct edge{int v,nxt;}e[N<<1];
void link(int x,int y){e[++cnt] = (edge){y,h[x]};h[x] = cnt;deg[y]++;}

void check(int x,int y,int w){
	for(int i = h[y],t;i;i = e[i].nxt){
		t = e[i].v; if(deg[t] == 1) return cannot[x] = 1,void();
	}f[x] += w;
}

void topsort(){
	int tot = 0; queue<int> q;
	for(int i = 1;i <= n;i++) if(!deg[i]) q.push(i),tot++;
	while(q.size()){
		int x = q.front(); q.pop();
		if(!q.size()) f[x] += n - tot;
		if(q.size() == 1) check(x,q.front(),n-tot);
		for(int i = h[x],y;i;i = e[i].nxt){
			y = e[i].v;
			deg[y]--; if(!deg[y]) q.push(y),tot++;
		}
	}
}


int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	for(int i = 1;i <= m;i++){u[i] = in,v[i] = in; link(u[i],v[i]);}
	topsort(); memset(h,0,sizeof(h)); memset(deg,0,sizeof(deg)); cnt = 0; for(int i = 1;i <= m;i++) link(v[i],u[i]);
	topsort(); int ans = 0;for(int i = 1;i <= n;i++) if(!cannot[i] && f[i] >= n-2) ans++;
	printf("%d\n",ans);
	return 0;
}
